# !/usr/bin/env python
# -*- coding:utf-8 -*-
# @FileName : zsj.py
# @Time     : 2024/5/18 1:13
# @Author   : Robot-Zsj
"""
description: 
"""
i1 = 123
o1 = 321

i2 = -123
o2 = -321


def reverse(x):
    INT_MIN, INT_MAX = -2 ** 31, 2 ** 31 - 1

    rev = 0
    while x != 0:
        if rev < INT_MIN // 10 + 1 or rev > INT_MAX // 10:
            return 0
        digit = x % 10
        if x < 0 < digit:
            digit -= 10
        x = (x - digit) // 10
        rev = rev * 10 + digit
    return rev


res1 = reverse(321)
print(res1)
res2 = reverse(-321)
print(res2)
